package com.rocpenghua.design.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author pengp
 * @date 2023年02月22日 11:05
 */
public class Employee implements Component {
    private String name;
    private String dept;
    private int salary;
    private List<Component> subordinates;

    //构造函数
    public Employee(String name,String dept, int sal) {
        this.name = name;
        this.dept = dept;
        this.salary = sal;
        subordinates = new ArrayList<Component>();
    }

    @Override
    public String toString(){
        return ("Employee :[ Name : "+ name
                +", dept : "+ dept + ", salary :"
                + salary+" ]");
    }

    @Override
    public void add(Component c) {
        subordinates.add(c);
    }

    @Override
    public void remove(Component c) {
        subordinates.remove(c);
    }

    @Override
    public List<Component> getAllChild() {
        return subordinates;
    }

    @Override
    public void operation() {
        System.out.println("Employee :[ Name : "+ name
                +", dept : "+ dept + ", salary :"
                + salary+" ]");
    }
}
